package com.xdf.testkafk.rocket;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.validator.Var;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author chanchaw
 * @create 2025-11-01 8:35
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = "imooc-study-rocketmq", // 消费指定的 topic
        consumerGroup = "cc-springboot-rocketmq-consumer-message-ext" // 消费者组，组内的多个消费者消费同一个 topic
)
public class RocketMQConsumerMessageExt implements RocketMQListener<MessageExt> {
    @Override
    public void onMessage(MessageExt messageExt) {
        String s = new String(messageExt.getBody());
        log.info("RocketMQConsumerMessageExt 方式获取消息数据，keys：[{}],value:[{}]", messageExt.getKeys(),s);
        log.info("传入参数 messageExt:[{}]", JSON.toJSONString(messageExt));
    }
}
